/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package csgui;
import csgui.entities.GridSimEntity;
import csgui.entities.Router;
import gridsim.ParameterException;
import gridsim.net.FIFOScheduler;
import gridsim.net.PacketScheduler;
import gridsim.net.RateControlledScheduler;
import gridsim.net.SCFQScheduler;
import gridsim.net.fnb.ARED;
import gridsim.net.fnb.FIFO;
import gridsim.net.fnb.RED;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
 *
 * @author robert
 */
public enum PacketSchedulerEnum {
    /**
     *
     */
    ARED("gridsim.net.fnb.ARED"),
    FIFO("gridsim.net.fnb.FIFO"),
    FIFO_SCHEDULER("gridsim.net.FIFOScheduler"),
    RATE_CONTROLLED_SCHEDULER("gridsim.net.RateControlledScheduler"),
    RED("gridsim.net.fnb.RED"),
    SCFQ_SCHEDULER("gridsim.net.SCFQScheduler");
    
    String className;
    
    PacketSchedulerEnum(String className)
    {
        this.className = className;
    }
    public Class getClassObject()
    {
        Class retVal = null;
        try {
            retVal =  Class.forName(className);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(PacketSchedulerEnum.class.getName()).log(Level.SEVERE, null, ex);
        }
        return retVal;
    }
    
    public PacketScheduler getPacketScheduler(Router router, GridSimEntity broker)
    {
        PacketScheduler scheduler;
        try {
            scheduler = scheduler = new FIFOScheduler(broker.getName()+"_FIFOScheduler");
        } catch (ParameterException ex) {
            Logger.getLogger(PacketSchedulerEnum.class.getName()).log(Level.SEVERE, null, ex);
        }
        try
        {
        if(this.equals(PacketSchedulerEnum.ARED))
                        {
                            //TODO: set max probability weight for dropping an incomplete packet (currently 0.0)
                            //TODO: set max buffer size for the router (currently mtu*number of ports)
                            //TODO: Set queue weight (currently set to 0.0)
                            scheduler = new ARED(broker.getName()+"_ARED",broker.getBaudRate(),0.0,(broker.getMtu()*(router.getGridSimEntity().size()+1)),0.0,router.getTrace());
                        }
                        else if(this.equals(PacketSchedulerEnum.FIFO))
                        {
                            //TODO: set max buffer size for the router (currently mtu*number of ports)
                            //TODO: Set queue weight (currently set to 0.0)
                            scheduler = new FIFO(broker.getName()+"_FIFO",broker.getBaudRate(),(broker.getMtu()*(router.getGridSimEntity().size()+1)),0.0,router.getTrace());
                        }
                        else if(this.equals(PacketSchedulerEnum.FIFO_SCHEDULER))
                        {
                            scheduler = new FIFOScheduler(broker.getName()+"_FIFOScheduler");
                        }
                        else if(this.equals(PacketSchedulerEnum.RATE_CONTROLLED_SCHEDULER))
                        {
                            //TODO: Set number of classes (currently 5)
                            scheduler = new RateControlledScheduler(broker.getName()+"_RateControlledScheduler",broker.getBaudRate(),5);
                        }
                        else if(this.equals(PacketSchedulerEnum.RED))
                        {
                            //TODO: max_buf_size - maximum buffer size for routers (currently mtu*number of ports)
                            //TODO: min_th - minimum threshold for RED (currently 0.0)
                            //TODO: max_th - maximum threshold for RED (currently 0.0)
                            //TODO: max_p - maximum drop probability for RED (currently 0.0)
                            //TODO: queue_weight - queue weight for RED (currently 0.0)
                            scheduler = new RED(broker.getName()+"_RED",broker.getBaudRate(),(broker.getMtu()*(router.getGridSimEntity().size()+1)),0.0,0.0,0.0,0.0,router.getTrace());
                        }
                        else if(this.equals(PacketSchedulerEnum.SCFQ_SCHEDULER))
                        {
                            scheduler = new SCFQScheduler(broker.getName()+"_SCFQScheduler");
                        }
        }
        catch(Exception e)
        {
            
        }
        return scheduler;
    }
}
